<%--
  Created by IntelliJ IDEA.
  User: kxk
  Date: 2021-05-12
  Time: 10:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户填写信息</title>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + path;
    %>
    <c:set var="bp" value="<%=basePath%>"></c:set>
    <link rel="stylesheet" type="text/css" href="${bp}/static/css/htmleaf-demo.css"/>
    <link rel="stylesheet" type="text/css" href="${bp}/static/css/normalize.css"/>
    <link rel="stylesheet" type="text/css" href="${bp}/static/css/login.css"/>
    <script type="text/javascript" src="${bp}/static/js/jquery.js"></script>
    <script type="text/javascript" src="${bp}/static/js/login.js"></script>
    <script src="${bp}/static/js/id_card_area.js" charset="utf-8"></script>
    <script>
        //获得前端得到的身份证信息
        function getbirthandage() {
            var uidcard=$.trim(document.getElementById("uidcard").value);
            var aaa= /(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if (uidcard!=""){
                console.log(uidcard);
                if (aaa.test(uidcard)) {
                    // 截取出生日期
                    var y = uidcard.substring(6, 10);
                    var m = uidcard.substring(10, 12);
                    var d = uidcard.substring(12, 14);
                    var pca1 = uidcard.substring(0, 6);
                    var birth = y + "-" + m + "-" + d;
                    //类型转换
                    var date = new Date(birth);
                    var date1 = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
                    console.log(date);
                    console.log(date1);
                    // 截取性别
                    var s = uidcard.substring(16, 17);
                    //将截取的信息传给页面展示
                    $("#dateForBirth").val(date);
                    $("#dateForBirth1").val(date1);
                    if (s % 2 == 0) {
                        $("#usex").val("女");
                    } else {
                        $("#usex").val("男");
                    }
                    //计算年龄
                    var age = (new Date()).getFullYear() - date.getFullYear();
                    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
                    if ((new Date()).getMonth() < date.getMonth() || ((new Date()).getMonth() == date.getMonth() && (new Date()).getDate() < date.getDate()))
                    {
                        if (age-1>=16){
                            $("#uage").val(age - 1);
                            var pca = id_card_area.getAreaByIdCard(pca1);
                            $("#upca").val(pca);
                        }
                        else{
                            document.getElementById("uIdCardmes").innerHTML = "您的身份证出生日期显示您未成年，请确认输入信息";
                            document.getElementById("uIdCardmes").style.color = "red";
                            $("#uidcard").val("");
                        }

                    }else{
                        $("#uage").val(age);
                        var pca = id_card_area.getAreaByIdCard(pca1);
                        $("#upca").val(pca)
                    }

                }else{
                    document.getElementById("uIdCardmes").innerHTML = "你输入的身份证长度或格式错误！";
                    document.getElementById("uIdCardmes").style.color = "red";
                    $("#uidcard").val("");
                    return false;
                }

            }else{
                document.getElementById("uIdCardmes").innerHTML= '身份证不能为空，请输入';
                document.getElementById("uIdCardmes").style.color = "red";
                return false;
            }
        }
    </script>
</head>
<body>
<div class="htmleaf-container">
    <div id="wrapper" class="login-page">
        <div id="login_form" class="form">
            <form class="login-form" action="info" method="post">
                <h3 style="text-align: center;margin-top:0"></h3>
                <input type="hidden" placeholder="序号" value="${onuser.uid}" name="uid"/>
                <input type="text" placeholder="姓名" id="uname" name="uname"  required="required"/>
                <input type="text" placeholder="昵称" id="unickname" name="unickname"required="required"/>
                <input type="text" placeholder="电话号码" id="utel" name="utel" value="${onuser.utel}" readonly="readonly"/>
                <input type="password" placeholder="密码" id="upass" name="upass" value="${onuser.upass}" required="required" />
                <input type="text" placeholder="身份证号" id="uidcard" name="uidcard"required="required" />
                <input type="text" placeholder="性别" id="usex" name="usex"required="required" placeholder="您的性别" onclick="getbirthandage()"/>
                <input type="text" placeholder="年龄" id="uage" name="uage"required="required"/>
                <input type="text" placeholder="配送地址" id="uaddress" name="uaddress"required="required"/>
                <input type="submit" value="确   认" style="background-color: #5cb85c"></button>
            </form>
        </div>
    </div>
</div>
</body>
</html>
